<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Stock extends CI_Controller {

    public function index() {
        $this->load->model('Products_model');
        $code = null;
        $description = null;
        $category = null;

        if ($this->input->post('code')) {
            $code = $this->input->post('code');
        }
        if ($this->input->post('description')) {
            $description = $this->input->post('description');
        }
        if ($this->input->post('category')) {
            $category = $this->input->post('category');
        }



        if ($code != null || $description != null || $category != null) {
            $products = $this->Products_model->search($code, $description, $category);
        } else {
            $products = array();
        }


        $codes = $this->Products_model->getcode(); // llama a getcode el cual tiene la consulta de los codigos
        $vars['codes'] = $codes; // lo coloca en una variable general


        $nameproducts = $this->Products_model->getnameproducts();
        $vars['nameproducts'] = $nameproducts;

        $vars['products'] = $products;
        $vars['productsxwarehouses'] = $this->Products_model->productsxwarehouses($code);    
        $vars['code'] = $code;
        $vars['description'] = $description;
        $vars['category'] = $category;


        $vars['content_view'] = 'products_list_index_2';
        $vars['menu'] = 'Stock';
        $this->load->view('template', $vars);
    }

    public function stockview() {

        $this->load->model('Products_model');
        
        $code = $this->input->post('code');
        
        $vars['listStock'] = $this->Products_model->find($code);
        $vars['productsxwarehouses'] = $this->Products_model->productsxwarehouses($code);
        $vars['codeProduct'] = $code;
        echo $this->load->view('stock_list_2', $vars);
    }

}

?>
